package com.tanhua.appservice;

import com.baidu.aip.face.AipFace;
import org.json.JSONObject;

import java.util.HashMap;

public class FaceDetect {
    //设置APPID/AK/SK
    public static final String APP_ID = "25389938";
    public static final String API_KEY = "4fr73x49Q1ApqiI5LpvQyx5l";
    public static final String SECRET_KEY = "FK622GVMr7uTR0wNf7v1D9aZn6nSYedY";

    public static void main(String[] args) {
        // 初始化一个AipFace
        AipFace client = new AipFace(APP_ID, API_KEY, SECRET_KEY);


        // 调用接口
        //String image = "https://jw-tianhua-image.oss-cn-beijing.aliyuncs.com/2021/12/21/e5581206-0982-4aa8-9e21-feef1985cf7b.jpg";

        String image = "https://jw-tianhua-image.oss-cn-beijing.aliyuncs.com/2021/12/21/37bbdb6e-f2c6-4272-a00c-1042485cb090.jpg";
        String imageType = "URL";

        // 传入可选参数调用接口
        HashMap<String, String> options = new HashMap<String, String>();
        options.put("face_field", "age");
        options.put("max_face_num", "1");
    
        // 人脸检测
        JSONObject res = client.detect(image, imageType,options);
        System.out.println(res.toString(2));

        Integer error_code = (Integer) res.get("error_code");

        System.out.println(error_code);
    }
}